package top.drinyeit.nongmao.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import top.drinyeit.nongmao.R;
import top.drinyeit.nongmao.app.Constant;
import top.drinyeit.nongmao.base.BaseActivity;
import top.drinyeit.nongmao.dialog.CenterDialog;
import top.drinyeit.nongmao.util.GlideCacheUtil;
import top.drinyeit.nongmao.util.SPUtil;

/**
 * Created by bigHead on 2017/11/15.
 */

public class SetupActivity extends BaseActivity{

    CenterDialog centerDialog;

    private RelativeLayout about_as,clearCache;//关于我们
    private TextView quit,cacheSize;//退出
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_setup);

        about_as = (RelativeLayout) findViewById(R.id.about_as);
        clearCache = findViewById(R.id.rl_clear_cache);
        quit = (TextView) findViewById(R.id.quit);
        cacheSize = findViewById(R.id.tv_cache_size);
        if (SPUtil.getShareString(Constant.USER_ID).equals("")){
            quit.setVisibility(View.GONE);
        }
        cacheSize.setText(GlideCacheUtil.getInstance().getCacheSize(this));

        init();
        setTitle(true,"设置");
    }

    @Override
    public void init() {
        //清除缓存
        clearCache.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                centerDialog = new CenterDialog(SetupActivity.this,R.layout.dialog_center);
                centerDialog.show();
                TextView textView = centerDialog.findViewById(R.id.dialog_text);
                textView.setText("是否清除缓存");

                TextView textView1 = centerDialog.findViewById(R.id.dialog_sure);
                textView1.setText("确定");
                textView1.setTextColor(getResources().getColor(R.color.red));
                textView1.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        GlideCacheUtil.getInstance().clearImageAllCache(SetupActivity.this);
                        showToast("清除缓存成功");
                        centerDialog.dismiss();
                        finish();
                    }
                });

                TextView textView2 = centerDialog.findViewById(R.id.dialog_cancel);
                textView2.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        centerDialog.dismiss();
                    }
                });
            }
        });

        //关于我们
        about_as.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(SetupActivity.this,AboutasActivity.class);
                startActivity(intent);
            }
        });

        quit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                centerDialog = new CenterDialog(SetupActivity.this,R.layout.dialog_center);
                centerDialog.show();
                TextView textView = centerDialog.findViewById(R.id.dialog_text);
                textView.setText("是否退出当前账户");

                TextView textView1 = centerDialog.findViewById(R.id.dialog_sure);
                textView1.setText("退出");
                textView1.setTextColor(getResources().getColor(R.color.red));
                textView1.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        SPUtil.setShareString(Constant.USER_ID,"");
                        centerDialog.dismiss();
                        finish();
                    }
                });

                TextView textView2 = centerDialog.findViewById(R.id.dialog_cancel);
                textView2.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        centerDialog.dismiss();
                    }
                });
            }
        });
    }
}
